package com.ceuer.mybatis.factory;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public class SessionFactory {
	public SqlSessionFactory factory;
	
	public SessionFactory() {
		try {
			Reader reader = Resources.getResourceAsReader("Mybatis-config.xml");
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			factory = builder.build(reader, "development");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public SqlSession getSession() {
		return factory.openSession();
	}
}